package server

import (
	"io/ioutil"
	"log"

	"gopkg.in/yaml.v1"
)

// Config config
type Config struct {
	Common struct {
		Version  string
		IsDebug  bool `yaml:"debug"`
		LogPath  string
		LogLevel string
	}

	Mysql struct {
		Addr     string
		Port     string
		Database string
		Acc      string
		Pw       string
	}

	Listen struct {
		WebAddr string
	}

	NovelsC struct {
		NovelsAddr string
	}
}

// Conf conf
var Conf = &Config{}

// var localIP = talents.LocalIP()
// var ssoUrl string

func init() {
	data, err := ioutil.ReadFile("novels.yaml")
	if err != nil {
		log.Fatal("read config error :", err)
	}

	err = yaml.Unmarshal(data, &Conf)
	if err != nil {
		log.Fatal("yaml decode error :", err)
	}

	// InitLogger()
	InitLogger(Conf.Common.LogPath, Conf.Common.LogLevel, Conf.Common.IsDebug)
}
